/*
 * Copyright (c) 2018 maoyan.com
 * All rights reserved.
 *
 */
package com.darren.euc.service.impl;

import com.darren.euc.dao.SuggestDao;
import com.darren.euc.entity.PageBean;
import com.darren.euc.entity.Suggest;
import com.darren.euc.service.SuggestService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 在这里编写类的功能描述
 *
 * @author fangwenhao
 * @created 2018/3/11
 */
@Service
public class SuggestServiceImpl implements SuggestService {

    @Autowired
    private SuggestDao suggestDao;

    @Override
    public PageBean queryForPageSuggestHQL(JSONObject data, Integer pageSize, int currentPage) {
        long userAreaId = data.getLong("userAreaId");
        int status = data.getInt("status");
        String HQL = " from Suggest where 1=1 ";
        if(userAreaId != -1 && status != -1){
            HQL = HQL + " and userAreaId = ? and status = ? order by addTime desc";
            return suggestDao.queryForPageByHQL(HQL, pageSize, currentPage,userAreaId,status);
        }else if (userAreaId == -1 && status != -1){
            HQL = HQL + " and status = ? order by addTime desc";
            return suggestDao.queryForPageByHQL(HQL, pageSize, currentPage,status);
        }else if (userAreaId != -1 && status == -1){
            HQL = HQL + " and userAreaId = ? order by addTime desc";
            return suggestDao.queryForPageByHQL(HQL, pageSize, currentPage,userAreaId);
        }else {
            HQL = HQL + " order by addTime desc ";
            return suggestDao.queryForPageByHQL(HQL, pageSize, currentPage);
        }
    }

    @Override
    public Suggest findById(Long id) {
        return  suggestDao.findById(id);
    }

    @Override
    public Suggest update(Suggest suggest) {
        return suggestDao.update(suggest);
    }

    @Override
    public Suggest save(Suggest suggest) {
        return suggestDao.save(suggest);
    }


}
